from datetime import datetime
from typing import List, Union, Literal

from sqlmodel import SQLModel, Field
from sqlalchemy import Column, Text

from app.models.base import EmptyStrToNone, PageParams


class SystemLogOperate(SQLModel, table=True):
    __tablename__ = "system_log_operate"

    id: int = Field(default=None, primary_key=True, index=True, nullable=False, description="主键")
    admin_id: int = Field(default=0, nullable=False, description="操作人ID")
    type: str = Field(default='', max_length=30, nullable=False, description="请求类型: GET/POST/PUT")
    title: str = Field(default='', max_length=30, nullable=True, description="操作标题")
    ip: str = Field(default='', max_length=30, nullable=False, description="请求IP")
    url: str = Field(default='', max_length=200, nullable=False, description="请求接口")
    method: str = Field(default='', max_length=200, nullable=False, description="请求方法")
    args: str = Field(sa_column=Column(Text()), description="请求参数")
    error: str = Field(sa_column=Column(Text()), description="错误信息")
    status: int = Field(default=1, nullable=False, description="执行状态: 1=成功, 2=失败")
    start_time: int = Field(default=0, nullable=False, description="开始时间")
    end_time: int = Field(default=0, nullable=False, description="结束时间")
    task_time: int = Field(default=0, nullable=False, description="执行耗时")
    create_time: int = Field(default=0, nullable=False, description="创建时间")


class SystemLogOperateListIn(PageParams):
    name: Union[str, None] = Field(default=None)
    code: Union[str, None] = Field(default=None)
    isStop: Union[int, None, EmptyStrToNone] = Field(default=None)


class SystemLogOperateListOut(SQLModel):
    data: list[SystemLogOperate]
    count: int
